#ifndef __FAKE_CAMERA_CONSUMER_H__
#define __FAKE_CAMERA_CONSUMER_H__

#include <binder/IPCThreadState.h>
#include <binder/IServiceManager.h>
#include <binder/ProcessState.h>

#include <gui/BufferQueue.h>
#include <gui/BufferQueueDefs.h>
#include <gui/ConsumerBase.h>
#include <ui/FenceTime.h>
#include <ui/GraphicBuffer.h>

using namespace android;

class FakeCameraConsumer : public ConsumerBase {
public:
    //FakeCameraConsumer(const sp<IGraphicBufferConsumer>& consumer, bool userFenceSync, bool controlledByApp = false);
    FakeCameraConsumer(const sp<IGraphicBufferConsumer>& consumer, bool controlledByApp = false);

    status_t setDefaultBufferSize(uint32_t width, uint32_t height);

//protected:

    static const uint64_t DEFAULT_USAGE_FLAGS = GraphicBuffer::USAGE_SW_READ_RARELY | GraphicBuffer::USAGE_SW_WRITE_RARELY;

    // abandonLocked overrides the ConsumerBase method to clear
    // mCurrentTextureImage in addition to the ConsumerBase behavior.
    virtual void abandonLocked();

    // dumpLocked overrides the ConsumerBase method to dump FakeCameraConsumer-
    // specific info in addition to the ConsumerBase behavior.
    virtual void dumpLocked(String8& result, const char* prefix) const;

    // acquireBufferLocked overrides the ConsumerBase method to update the
    // mEglSlots array in addition to the ConsumerBase behavior.
    virtual status_t acquireBufferLocked(BufferItem *item, nsecs_t presentWhen,
            uint64_t maxFrameNumber = 0) override;

    // releaseBufferLocked overrides the ConsumerBase method to update the
    // mEglSlots array in addition to the ConsumerBase.
    virtual status_t releaseBufferLocked(int slot,
            const sp<GraphicBuffer> graphicBuffer,
            EGLDisplay display, EGLSyncKHR eglFence) override;

    status_t acquireBuffer(BufferItem *item, nsecs_t presentWhen, uint64_t maxFrameNumber = 0);
    status_t releaseBuffer(int slot);

    status_t getGraphicBuffer(int slot, sp<GraphicBuffer> &graphicBuffer);

private:
   // freeBufferLocked frees up the given buffer slot. If the slot has been
    // initialized this will release the reference to the GraphicBuffer in that
    // slot and destroy the EGLImage in that slot.  Otherwise it has no effect.
    //
    // This method must be called with mMutex locked.
    virtual void freeBufferLocked(int slotIndex);

    uint32_t mDefaultWidth, mDefaultHeight;    
};

#endif